package ru.ncedu.java.vlku.hrs.uil.cmd;

import ru.ncedu.java.vlku.hrs.bll.HRSManager;
import ru.ncedu.java.vlku.hrs.bll.HRSManagerFactory;
import ru.ncedu.java.vlku.hrs.model.Cargo;
import ru.ncedu.java.vlku.hrs.model.Shop;
import ru.ncedu.java.vlku.hrs.model.ShopCargoAvailability;

public class AddToShop implements Command {
    // addto shop <shop_id> <cargo_id> <quantity>
    @Override
    public void execute( String[] args ) {
        if (args.length != 5) {
            throw new IllegalArgumentException();
        }
        Long shop_id = Long.parseLong(args[2]);
        Long cargo_id = Long.parseLong(args[3]);
        Long quantity = Long.parseLong(args[4]);

        HRSManager manager = HRSManagerFactory.getInstance().getHRSManager();
        Shop shop = manager.getShopById(shop_id);
        Cargo cargo = manager.getCargoById(cargo_id);
        ShopCargoAvailability sca = new ShopCargoAvailability(shop, cargo, quantity);
        manager.createShopCargoAvailability(sca);
    }
}
